package com.hzy.friend.service.impl;

import com.hzy.base.exception.CustomException;
import com.hzy.friend.dao.UserDao;
import com.hzy.friend.entity.User;
import com.hzy.friend.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* 请替换User介绍 service接口实现
*
* @author: 请替换作者
* @version: 1.0
* @datetime: 2019-03-01 17:33:27
*/
@Service
@Slf4j
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public void save(User user) throws Exception {
        userDao.save(user);
    }

    @Override
    public List<User> find(User user) throws Exception {
        return userDao.find(user);
    }

    @Override
    public void remove(User user) throws Exception {
        if(StringUtils.isBlank(user.getIds())){
            throw new CustomException("主键ids不能为空");
        }
        userDao.remove(user);
    }

    @Override
    public void remove(String userId) throws Exception {
        if(StringUtils.isBlank(userId)){
            throw new CustomException("主键id不能为空");
        }
        userDao.remove(userId);
    }

    @Override
    public void modify(User user) throws Exception {
        if(StringUtils.isBlank(user.getUserId())){
            throw new CustomException("主键id不能为空");
        }
        userDao.update(user);
    }

    @Override
    public void resort(User user) throws Exception {
        if(StringUtils.isBlank(user.getIds())){
            throw new CustomException("ids不能为空");
        }
        userDao.resort(user);
    }

    @Override
    public User findById(String userId) throws Exception {
        if(StringUtils.isBlank(userId)){
            throw new CustomException("主键id不能为空");
        }
        User result = userDao.findById(userId);
        if (null == result) {
            throw new CustomException("未查到数据");
        }
        return result;
    }
}

